package 剑指offer.Month7_07.day18;

import java.util.ArrayList;

public class 和为S的连续正数序列 {
    public ArrayList<ArrayList<Integer> > FindContinuousSequence(int sum) {
        ArrayList<ArrayList<Integer>> res = new ArrayList<>();
        int resNum = 0;
        for (int i = 1,j = 2; i < j;) {
            resNum = (j - i + 1) * (i + j)/2;
            if(resNum == sum){
                ArrayList<Integer> arr = new ArrayList<>();
                for(int k = i;k <= j;k++){
                    arr.add(k);
                }
                res.add(arr);
                j++;
            }else if(resNum > sum){
                i++;
            }else{
                j++;
            }
        }
        return res;
    }
}
